//
//  WWGoodsDetails.m
//  Shopping
//
//  Created by 孙博 on 16/8/23.
//  Copyright © 2016年 张湾湾. All rights reserved.
//

#import "WWGoodsDetails.h"
#import <UIImageView+WebCache.h>

@interface WWGoodsDetails ()

@property (nonatomic, weak)UIImageView *headImgView;

@property (nonatomic, weak)UITableView *table;

@property (nonatomic, weak)UIImageView *endImgView;

@end

@implementation WWGoodsDetails

- (void)viewDidLoad{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor orangeColor];
    [self setupUI];
}
/**
 *  setter方法
 *
 *  @param model
 */
- (void)setModel:(WWFreshSellModel *)model{
    _model = model;
//    [self.headImgView sd_setImageWithURL:[NSURL URLWithString:model.img]];
    
}

/**
 *   设置UI
 */
- (void)setupUI{
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    UIImageView *head = [[UIImageView alloc]init];
    self.headImgView = head;
    head.backgroundColor = [UIColor redColor];
    [self.view addSubview:head];
    
    UITableView *table = [[UITableView alloc]init];
    self.table = table;
    [self.view addSubview:table];
    
    UIImageView *end = [[UIImageView alloc]init];
    self.endImgView = end;
    [self.view addSubview:end];
    
    [self.headImgView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view);
        make.leading.trailing.equalTo(self.view);
        make.height.equalTo(300);
    }];
    
    table.estimatedRowHeight = 200;
    table.rowHeight = UITableViewAutomaticDimension;
    [self.table makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(head.bottom);
        make.trailing.leading.equalTo(self.view);
    }];
    
    [end makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(table.bottom);
        make.leading.trailing.equalTo(self.view);
        make.height.equalTo(600);
    }];
    
    // 左
    UIButton *leftBtn = [[UIButton alloc]init];
    [leftBtn setImage:[UIImage imageNamed:@"v2_goback"] forState:UIControlStateNormal];
    leftBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    [leftBtn sizeToFit];
    [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    // 右边
    UIButton *rightBtn = [[UIButton alloc]init];
    [rightBtn setTitle:@"分享" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [rightBtn sizeToFit];
    [rightBtn addTarget:self action:@selector(shareApp) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
}

// 按钮点击
- (void)shareApp{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"分享" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *actVXFriend = [UIAlertAction actionWithTitle:@"微信好友" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"分享给微信好友");
    }];

    
    UIAlertAction *actVXCicle = [UIAlertAction actionWithTitle:@"微信朋友圈" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"分享给微信朋友圈");
    }];
    //
    
    [alert addAction:actVXFriend];
    [alert addAction:actVXCicle];
    [self presentViewController:alert animated:YES completion:nil];
}
- (void)goBack{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
